﻿using System;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;

namespace ArunimaErp.WebForm
{
    public partial class OrderStatusForm : System.Web.UI.Page
    {
        private ReportDocument rptDoc = new ReportDocument();
        private rerpDataSet orderStatusDs = new rerpDataSet(); // .xsd file name
        private DataTable orderStatusDt = new DataTable();

        protected void Page_Load(object sender, EventArgs e)
        {
            // Just set the name of data table
            orderStatusDt.TableName = "orderStatusTable";

            string _query = "select "
                                + " BuyerName, "
                                + " DevisionName, "
                                + " OrderQuantity, "
                                + " ExitDate, "
                                + " sum(TodaySewing) as TotalSewing, "
                                + " Capacity "
                                + " from BuyerInfo b, devision d, StyleInfo s, "
                                + " PoStyle ps left join ProductionDailyReport dr "
                                + " on ps.PoStyleId = dr.PoStyleId "
                                + " where b.BuyerId = s.BuyerId and "
                                + " d.DevisionId = s.DevisionId and "
                                + " s.StyleId = ps.StyleId "
                                + " group by ps.PoStyleId"
                                ;

            orderStatusDt = DatabaseHelper.select(_query); //This function is located below this function
            orderStatusDs.Tables["OrderStatus"].Merge(orderStatusDt);
            // Your .rpt file path will be below
            rptDoc.Load(Server.MapPath("../WebForm/OrderStatusReport.rpt"));

            //set dataset to the report viewer.
            rptDoc.SetDataSource(orderStatusDs);
            CrystalReportViewer1.ReportSource = rptDoc;
        }

        protected void Page_Unload(object sender, EventArgs e)
        {
            rptDoc.Close();
            rptDoc.Dispose();
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Home");
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Response.Redirect("/WebForm/WipReportForm.aspx");
        }
    }
}